package com.web.filemanage.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.web.common.dao.FileInfoMapper;
import com.web.common.dao.FileMapper;
import com.web.common.po.File;
import com.web.common.po.FileInfo;
import com.web.common.utils.RandNum;
import com.web.filemanage.service.IFileService;

@Service("fileService")
public class FileServiceImp implements IFileService {
	
	@Resource
	private FileMapper fileMapper;
	
	@Resource
	private FileInfoMapper fileInfoMapper;
	
	@Override
	@Transactional
	public void upload(FileInfo info) {
		// TODO Auto-generated method stub
		Date current = new Date();
		DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		String fileUid = format.format(current)+RandNum.randNum(6);
		
		File file = new File();
		file.setFileCreatetime(current);
		file.setFileStatus(0);
		file.setFileUid(fileUid);
		file.setIsdelete(0);
		
		info.setFileUid(fileUid);
		
		fileMapper.insert(file);
		fileInfoMapper.insert(info);
		
	}

	@Override
	public FileInfo getInfo(String uid) {
		// TODO Auto-generated method stub
		
		FileInfo fileInfo = fileInfoMapper.selectByPrimaryKey(uid);
		return fileInfo;
	}

	@Override
	public List<FileInfo> queryAllFile() {
		// TODO Auto-generated method stub
		return fileInfoMapper.queryAll();
	}

}
